package uit.uthuoc.fragment;

import uit.uthuoc.dal.DrugDAO;
import uit.uthuoc.dal.DrugDTO;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.uit.uthuoc.R;

public class DrugDetailsFragment extends Fragment {
	
	private static final String EXTRA_ID = "uit.uthuoc.fragment.DrugDetailsFragment.EXTRA_ID";
	
	private DrugDTO mDrug;
	private TextView mTextView;
	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {		
		super.onCreate(savedInstanceState);
		
		int index = getArguments().getInt(EXTRA_ID);
		mDrug = DrugDAO.getDAO().getDrug(index);
	}


	@Override
	public View onCreateView(LayoutInflater inflater,
			@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.drug_details_layout, container, false);
		
		mTextView = (TextView) v.findViewById(R.id.details_layout_drug_name);
		mTextView.setText(mDrug.getName());
		
		return v;
	}


	// Create a new DrugDetailsFragment base on index, 
	// in product index should be the ID of data table.
	public static DrugDetailsFragment newInstance(int index) {
		Bundle args = new Bundle();
		args.putInt(EXTRA_ID, index);
		
		DrugDetailsFragment fragment = new DrugDetailsFragment();
		fragment.setArguments(args);
		
		return fragment;
	}
}
